﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using HIWSystem.Common;
using HIWSystem.Helpers;
using HIWSystem.Models;

namespace HIWSystem.ViewModel
{
    public class TUNNINGInfoQueryViewModel : ViewModelBase
    {
        #region 属性
        private bool IsFirstFilterPNFlag = true; //首次过滤机种信息标志位
        private bool IsFirstFilterActorFlag = true;//首次过滤工号信息标志位
        DataTable dtDetails = new DataTable();//详细信息数据表《创建全局变量便于导出数据》
        DataTable dtTunning = new DataTable();//调试良率信息《创建全局变量便于导出数据》
        TrackingCombineSnEntity trackingCombineSnEntity = null;
        //TrackingEntity trackingEntity = null;
        ObservableCollection<PartNumberEntity> backupPNs = null; //备份机种原始记录
        ObservableCollection<EmployeesEntity> backupActors = null;//备份工号原始记录
        private string sn;
        /// <summary>
        ///  序列号
        /// </summary>
        public string SN
        {
            get { return sn; }
            set { sn = value; this.RaisePropertyChanged(() => SN); }
        }
        private string wo;
        /// <summary>
        /// 工单
        /// </summary>
        public string WO
        {
            get { return wo; }
            set { wo = value; this.RaisePropertyChanged(() => WO); }
        }
        private ObservableCollection<TrackingEntity> results;
        /// <summary>
        /// 结果集
        /// </summary>
        public ObservableCollection<TrackingEntity> Results
        {
            get { return results; }
            set { results = value; this.RaisePropertyChanged(() => Results); }
        }
        private TrackingEntity selectedResult;
        /// <summary>
        /// 选择的结果项
        /// </summary>
        public TrackingEntity SelectedResult
        {
            get { return selectedResult; }
            set { selectedResult = value; this.RaisePropertyChanged(() => SelectedResult); }
        }
        private string result;
        /// <summary>
        /// 选择的结果值
        /// </summary>
        public string Result
        {
            get { return result; }
            set { result = value; this.RaisePropertyChanged(() => Result); }
        }
        private bool isOpenComboResultDropDown;
        /// <summary>
        /// 是否展开结果下拉列表框
        /// </summary>
        public bool IsOpenComboResultDropDown
        {
            get { return isOpenComboResultDropDown; }
            set { isOpenComboResultDropDown = value; this.RaisePropertyChanged(() => IsOpenComboResultDropDown); }
        }
        private string searchResultText;
        /// <summary>
        /// 输入的查询文本
        /// </summary>
        public string SearchResultText
        {
            get { return searchResultText; }
            set { searchResultText = value; this.RaisePropertyChanged(() => SearchResultText); }
        }
        private string tunningStation;
        /// <summary>
        /// 调试的站位
        /// </summary>
        public string TunningStation
        {
            get { return tunningStation; }
            set { tunningStation = value; this.RaisePropertyChanged(() => TunningStation); }
        }
        private string tunningSource;
        /// <summary>
        /// 调试的来源
        /// </summary>
        public string TunningSource
        {
            get { return tunningSource; }
            set { tunningSource = value; this.RaisePropertyChanged(() => TunningSource); }
        }
        private string actor="无";
        /// <summary>
        /// 工号
        /// </summary>
        public string Actor
        {
            get { return actor; }
            set { actor = value; this.RaisePropertyChanged(() => Actor); }
        }
        private string startTime;
        /// <summary>
        /// 开始时间
        /// </summary>
        public string StartTime
        {
            get { return startTime; }
            set { startTime = value; this.RaisePropertyChanged(() => StartTime); }
        }
        private string stopTime;
        /// <summary>
        /// 结束时间
        /// </summary>
        public string StopTime
        {
            get { return stopTime; }
            set { stopTime = value; this.RaisePropertyChanged(() => StopTime); }
        }
      
        private ObservableCollection<TrackingCombineSnEntity> details;
        /// <summary>
        /// 调试详细信息
        /// </summary>
        public ObservableCollection<TrackingCombineSnEntity> Details
        {
            get { return details; }
            set { details = value; this.RaisePropertyChanged(() => Details); }
        }

        private bool isEnabledQueryButton=true;
        /// <summary>
        /// 是否启用查询按钮
        /// </summary>
        public bool IsEnabledQueryButton
        {
            get { return isEnabledQueryButton; }
            set { isEnabledQueryButton=value; this.RaisePropertyChanged(() => IsEnabledQueryButton); }
        }
        private Visibility isVisibleLoading=Visibility.Collapsed;
        /// <summary>
        /// 是否显示加载图标
        /// </summary>
        public Visibility IsVisibleLoading
        {
            get { return isVisibleLoading; }
            set { isVisibleLoading = value; this.RaisePropertyChanged(() => IsVisibleLoading); }
        }
        private ObservableCollection<TunningYieldEntity> tunningYields;
        /// <summary>
        /// 调试良率数据集
        /// </summary>
        public ObservableCollection<TunningYieldEntity> TunningYields
        {
            get { return tunningYields; }
            set { tunningYields = value; this.RaisePropertyChanged(() => TunningYields); }
        }
        private bool isCheckedDaily=false;
        /// <summary>
        /// 是否选中当天
        /// </summary>
        public bool IsCheckedDaily
        {
            get { return isCheckedDaily; }
            set { isCheckedDaily = value; this.RaisePropertyChanged(() => IsCheckedDaily); }
        }
        private bool isEnabledExportButton=true;
        /// <summary>
        /// 是否启用导出按钮
        /// </summary>
        public bool IsEnabledExportButton
        {
            get { return isEnabledExportButton; }
            set { isEnabledExportButton = value; this.RaisePropertyChanged(() => IsEnabledExportButton); }
        }
        private string pn = "无";
        /// <summary>
        /// 机种信息
        /// </summary>
        public string PN
        {
            get { return pn; }
            set { pn = value; this.RaisePropertyChanged(() => PN); }
        }
        private string searchPNText;
        /// <summary>
        /// ComboBox文本框输入的搜索文本
        /// </summary>
        public string SearchPNText
        {
            get { return searchPNText; }
            set { searchPNText = value; this.RaisePropertyChanged(() => SearchPNText); }
        }
        private PartNumberEntity selectedPartNumber;
        /// <summary>
        ///  选中的机种
        /// </summary>
        public PartNumberEntity SelectedPartNumber
        {
            get { return selectedPartNumber; }
            set { selectedPartNumber = value; this.RaisePropertyChanged(() => SelectedPartNumber); }
        }

        private ObservableCollection<PartNumberEntity> pns;
        /// <summary>
        /// 机种信息
        /// </summary>
        public ObservableCollection<PartNumberEntity> PNs
        {
            get { return pns; }
            set { pns = value; this.RaisePropertyChanged(() => PNs); }
        }
        private string selectedPN;
        /// <summary>
        /// 选中的机种
        /// </summary>
        public string SelectedPN
        {
            get { return selectedPN; }
            set { selectedPN = value; this.RaisePropertyChanged(() => SelectedPN); }
        }
        private bool comboPNOpen;
        /// <summary>
        /// 是否打开机种下拉Panel
        /// </summary>
        public bool ComboPNOpen
        {
            get { return comboPNOpen; }
            set { comboPNOpen = value; this.RaisePropertyChanged(() => ComboPNOpen); }
        }

        private ObservableCollection<TrackingEntity> sequences;
        /// <summary>
        /// 测序集合
        /// </summary>
        public ObservableCollection<TrackingEntity> Sequences
        {
            get { return sequences; }
            set { sequences = value; this.RaisePropertyChanged(() => Sequences); }
        }
        private TrackingEntity selectedSequence;
        /// <summary>
        /// 选择的测试项
        /// </summary>
        public TrackingEntity SelectedSequence
        {
            get { return selectedSequence; }
            set { selectedSequence = value; this.RaisePropertyChanged(() => SelectedSequence); }
        }
        private string sequence="1";
        /// <summary>
        /// 选择的测序值
        /// </summary>
        public string Sequence
        {
            get { return sequence; }
            set { sequence = value; this.RaisePropertyChanged(() => Sequence); }
        }
        private ObservableCollection<EmployeesEntity> actors;
        /// <summary>
        /// 工号集合
        /// </summary>
        public ObservableCollection<EmployeesEntity> Actors
        {
            get { return actors; }
            set { actors = value; this.RaisePropertyChanged(() => Actors); }
        }
        private EmployeesEntity selectedActor;
        /// <summary>
        /// 选择的员工实体类
        /// </summary>
        public EmployeesEntity SelectedActor
        {
            get { return selectedActor; }
            set { selectedActor = value; this.RaisePropertyChanged(() => SelectedActor); }
        }
        private bool isOpenComboActorDropDown;
        /// <summary>
        /// 是否打开工号下拉框Panel
        /// </summary>
        public bool IsOpenComboActorDropDown
        {
            get { return isOpenComboActorDropDown; }
            set { isOpenComboActorDropDown = value; this.RaisePropertyChanged(() => IsOpenComboActorDropDown); }
        }
        private string searchActorText;
        /// <summary>
        /// 查询的工号信息
        /// </summary>
        public string SearchActorText
        {
            get { return searchActorText; }
            set { searchActorText = value; this.RaisePropertyChanged(() => SearchActorText); }
        }

        #endregion

        #region 命令
        private RelayCommand queryCmd;

        public RelayCommand QueryCmd
        {
            get 
            {
                if (queryCmd==null)
                {
                    queryCmd = new RelayCommand(QueryTunningAsync);
                }
                return queryCmd;
            }
            set { queryCmd = value; }
        }
        private RelayCommand loadedPageCmd;

        public RelayCommand LoadedPageCmd
        {
            get 
            {
                if (loadedPageCmd == null)
                {
                    loadedPageCmd = new RelayCommand(LoadedPage);
                }
                return loadedPageCmd; 
            }
            set { loadedPageCmd = value; }
        }
        private RelayCommand<bool?> checkedDailyCmd;

        public RelayCommand<bool?> CheckedDailyCmd
        {
            get {
                if (checkedDailyCmd==null)
                {
                    checkedDailyCmd = new RelayCommand<bool?>(CheckedDailyHandle);
                }
                return checkedDailyCmd; }
            set { checkedDailyCmd = value; }
        }
        private RelayCommand<TunningYieldEntity> showTunningDetatilsInfoCmd;

        public RelayCommand<TunningYieldEntity> ShowTunningDetatilsInfoCmd
        {
            get {
                if (showTunningDetatilsInfoCmd==null)
                {
                    showTunningDetatilsInfoCmd = new RelayCommand<TunningYieldEntity>(ShowTunningDetailsInfoAsync);
                }
                return showTunningDetatilsInfoCmd; }
            set { showTunningDetatilsInfoCmd = value; }
        }
        private RelayCommand exportCmd;

        public RelayCommand ExportCmd
        {
            get {
                exportCmd = exportCmd ?? new RelayCommand(ExportAsync);
                return exportCmd; }
            set { exportCmd = value; }
        }
        private RelayCommand filterPNCmd;

        public RelayCommand FilterPNCmd
        {
            get
            {
                filterPNCmd = filterPNCmd ?? new RelayCommand(FilterPN);
                return filterPNCmd;
            }
            set { filterPNCmd = value; }
        }
        private RelayCommand filterActorCmd;

        public RelayCommand FilterActorCmd
        {
            get {
                filterActorCmd = filterActorCmd ?? new RelayCommand(FilterActor);
                return filterActorCmd; }
            set { filterActorCmd = value; }
        }

        #endregion

        #region 方法
        /// <summary>
        /// 页面加载
        /// </summary>
        private void LoadedPage()
        {
            //填充序列信息
            Sequences = new ObservableCollection<TrackingEntity>();
            Sequences.Add(new TrackingEntity { TestSequence = "全部" });
            Sequences.Add(new TrackingEntity { TestSequence = "首次" });
            Sequences.Add(new TrackingEntity { TestSequence = "最后一次" });
            //填充机种信息到下拉列表框中
            FillPNsToComboBox();
            //填工号位信息到下拉列表框中
            FillActorToComboBox();
        }
        /// <summary>
        /// 填充机种信息
        /// </summary>
        private void FillPNsToComboBox()
        {
            DataTable dtPNs = new DataTable();
            dtPNs = BusinessProcess.GetPNs(EnumPNType.All);
            PNs = new ObservableCollection<PartNumberEntity>();
            PNs.Add(new PartNumberEntity { PN = "无" });
            for (int i = 0; i < dtPNs.Rows.Count; i++)
            {
                PNs.Add(new PartNumberEntity
                {
                    PN = dtPNs.Rows[i]["PartNumber"].ToString()
                });
            }
        }
        /// <summary>
        /// 填充工号信息
        /// </summary>
        private void FillActorToComboBox()
        {
            DataTable dtActors = new DataTable();
            dtActors = BusinessProcess.GetAllEmployeeInfo();
            Actors = new ObservableCollection<EmployeesEntity>();
            Actors.Add(new EmployeesEntity { UserNo = "无" });
            for (int i = 0; i < dtActors.Rows.Count; i++)
            {
                Actors.Add(new EmployeesEntity
                {
                    UserNo = dtActors.Rows[i]["UserNo"].ToString()
                });
            }
        }
        /// <summary>
        /// 查询调试信息
        /// </summary>
        private async void QueryTunningAsync()
        {
            string retMsg = string.Empty;
            string[] arrMsg = new string[2];

            if (IsEnabledExportButton == false)
            {
                MessageBox.Show("正在导出报告...待导出完成以后再查询", "软件温馨提示!", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            //ObservableCollection<TrackingEntity> tmpTunningLogs = new ObservableCollection<TrackingEntity>();
            ObservableCollection<TunningYieldEntity> tmpTunningYield = new ObservableCollection<TunningYieldEntity>();
            try
            {
                await Task.Run(() => 
                {
                    Application.Current.Dispatcher.BeginInvoke((Action)(() => {
                        //禁用查询按钮
                        this.IsEnabledQueryButton = false;
                        //显示加载图标
                        this.IsVisibleLoading = Visibility.Visible;
                        TunningYields = new ObservableCollection<TunningYieldEntity>();
                        //TunningLogs = new ObservableCollection<TrackingEntity>();
                    }));
                    trackingCombineSnEntity = new TrackingCombineSnEntity
                    {
                        StartTime = this.StartTime ?? "",
                        StopTime = this.StopTime ?? "",
                        PN = this.PN == "无" ? "" : this.PN ?? "",
                        Actor = this.Actor == "无" ? "" : this.Actor ?? "",
                        TestSequence = this.Sequence ?? "*"
                    };
                    dtTunning = new DataTable();
                    retMsg = BusinessProcess.QueryTunning(trackingCombineSnEntity, out dtTunning);
                    arrMsg = retMsg.Split('|');
                    if (arrMsg[0] == "OK")
                    {
                        for (int i = 0; i < dtTunning.Rows.Count; i++)
                        {
                            tmpTunningYield.Add(new TunningYieldEntity {

                                PN = dtTunning.Rows[i]["PN"].ToString(),
                                FirstTunning = dtTunning.Rows[i]["FirstTunning"].ToString(),
                                ATE = dtTunning.Rows[i]["ATE"].ToString(),
                                Rework = dtTunning.Rows[i]["Rework"].ToString(),
                                Revisit = dtTunning.Rows[i]["Revisit"].ToString(),
                                OBA = dtTunning.Rows[i]["OBA"].ToString(),
                                Defect = dtTunning.Rows[i]["Defect"].ToString(),
                                Yield = dtTunning.Rows[i]["Yield"].ToString(),
                            });
                        }
                        Application.Current.Dispatcher.BeginInvoke((Action)(() => {
                            //this.TunningLogs = tmpTunningLogs;
                            this.TunningYields = tmpTunningYield;
                        }));
                    }
                    else
                    {
                       MessageBox.Show(arrMsg[1],"软件温馨提示",MessageBoxButton.OK,MessageBoxImage.Error);
                    }
                    Application.Current.Dispatcher.BeginInvoke((Action)(() => {
                        this.IsVisibleLoading = Visibility.Collapsed;//隐藏加载动画
                        this.IsEnabledQueryButton = true;
                    }));
                   
                });
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(string.Format("执行方法【{0}】出现错误【{1}】", nameof(QueryTunningAsync), ex.Message), ex);
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 导出报告《异步》
        /// </summary>
        private async void ExportAsync()
        {
            if (dtTunning.Rows.Count == 0 && dtDetails.Rows.Count == 0)
            {
                MessageBox.Show("没有数据需要导出", "软件温馨提示!", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (IsEnabledQueryButton == false)
            {
                MessageBox.Show("正在查询数据...待查询完再导出", "软件温馨提示!", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            //保存数据之前先关闭Excel
            BusinessProcess.KillProcess("EXCEL");
            this.IsEnabledExportButton = false;
            //创建Excel  
            Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel.Workbook excelWB = excelApp.Workbooks.Add(System.Type.Missing);    //创建工作簿（WorkBook：即Excel文件主体本身）  
            Microsoft.Office.Interop.Excel.Worksheet excelWS = (Microsoft.Office.Interop.Excel.Worksheet)excelWB.Worksheets[1];   //创建工作表（即Excel里的子表sheet） 1表示在子表sheet1里进行数据导出  
            //excelWS.Cells.NumberFormat = "@";     //  如果数据中存在数字类型 可以让它变文本格式显示  
            //将数据导入到工作表的单元格
            await Task.Run(() => {
                //显示加载动画
                this.IsVisibleLoading = Visibility.Visible;
                for (int i = 0; i < dtTunning.Columns.Count; i++)
                {
                    excelWS.Cells[1, i + 1] = dtTunning.Columns[i].ColumnName;
                }

                for (int i = 0; i < dtTunning.Rows.Count; i++)
                {
                    for (int j = 0; j < dtTunning.Columns.Count; j++)
                    {
                        excelWS.Cells[i + 2, j + 1] = dtTunning.Rows[i][j].ToString();   //Excel单元格第一个从索引1开始 
                    }
                }
                //创建工作表（Worksheet：工作表，即Excel里的子表sheet）
                excelWS = (Microsoft.Office.Interop.Excel.Worksheet)excelWB.Worksheets.Add(System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                //设置表名
                excelWS.Name = "Details";
                //将数据导入到工作表的单元格
                for (int i = 0; i < dtDetails.Columns.Count; i++)
                {
                    excelWS.Cells[1, i + 1] = dtDetails.Columns[i].ColumnName;
                }

                for (int i = 0; i < dtDetails.Rows.Count; i++)
                {
                    for (int j = 0; j < dtDetails.Columns.Count; j++)
                    {
                        excelWS.Cells[i + 2, j + 1] = dtDetails.Rows[i][j].ToString();   //Excel单元格第一个从索引1开始 
                    }
                }
                //关闭加载动画
                this.IsVisibleLoading = Visibility.Collapsed;
            });

            //使用对话框让用户选择保存位置和填写保存的文件名
            Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();

            sfd.Filter = "Excel工作簿(*.xlsx)|*.xlsx";

            sfd.FilterIndex = 1;

            sfd.RestoreDirectory = true;

            if (sfd.ShowDialog() == true)
            {
                string localFilePath = sfd.FileName.ToString(); //获得文件路径
                string fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1); //获取文件名，不带路径

                //获取文件路径，不带文件名
                //FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));
                //给文件名前加上时间
                //newFileName = DateTime.Now.ToString("yyyyMMdd") + fileNameExt;
                //在文件名里加字符
                //saveFileDialog1.FileName.Insert(1,"dameng");
                //System.IO.FileStream fs = (System.IO.FileStream)sfd.OpenFile();//输出文件fs输出带文字或图片的文件，就看需求了
                excelWB.SaveAs(localFilePath);  //将其进行保存到指定的路径  
                excelWB.Close();
                excelApp.Quit();  //KillAllExcel(excelApp); 释放可能还没释放的进程
                MessageBox.Show("导出表格成功!");
                System.Diagnostics.Process.Start(localFilePath);//保存完成后  打开文件
            }
            this.IsEnabledExportButton = true;
        }

        private void CheckedDailyHandle(bool? obj)
        {
            if (obj!=null && obj==true)
            {
                this.IsCheckedDaily = true;
                this.StartTime = DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:01";
                this.StopTime = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
            }
        }
        private async void ShowTunningDetailsInfoAsync(TunningYieldEntity obj)
        {
            if (obj!=null)
            {
                string retMsg = string.Empty;
                string[] arrMsg = new string[2];

                try
                {
                    ObservableCollection<TrackingCombineSnEntity> tmpDetails = new ObservableCollection<TrackingCombineSnEntity>();
                    Details = new ObservableCollection<TrackingCombineSnEntity>();
                    dtDetails = new DataTable();
                    await Task.Run(() => {
                        Application.Current.Dispatcher.BeginInvoke((Action)(() => {
                            this.IsVisibleLoading = Visibility.Visible;
                        }));
                        TrackingCombineSnEntity tmpEntity = new TrackingCombineSnEntity {
                            PN = obj.PN == "汇总" ? "" : obj.PN ?? "",
                            Actor = trackingCombineSnEntity.Actor ?? "",
                            TestSequence = trackingCombineSnEntity.TestSequence ?? "*",
                            StartTime= trackingCombineSnEntity.StartTime??"",
                            StopTime=trackingCombineSnEntity.StopTime??""
                        };
                        retMsg = BusinessProcess.QueryTunningDetails(tmpEntity, out dtDetails);
                        arrMsg = retMsg.Split('|');
                        if (arrMsg[0] == "Y")
                        {
                            for (int i = 0; i < dtDetails.Rows.Count; i++)
                            {
                                tmpDetails.Add(new TrackingCombineSnEntity {
                                 Sn=dtDetails.Rows[i]["Sn"].ToString()??"",
                                    PN = dtDetails.Rows[i]["PN"].ToString() ?? "",
                                    WO = dtDetails.Rows[i]["WO"].ToString() ?? "",
                                    Station = dtDetails.Rows[i]["Station"].ToString() ?? "",
                                    Result = dtDetails.Rows[i]["Result"].ToString() ?? "",
                                    FailDescription = dtDetails.Rows[i]["FailDescription"].ToString() ?? "",
                                    FailValue = dtDetails.Rows[i]["FailValue"].ToString() ?? "",
                                    EquipmentName = dtDetails.Rows[i]["EquipmentName"].ToString() ?? "",
                                    TestSequence = dtDetails.Rows[i]["TestSequence"].ToString() ?? "",
                                    StartTime = dtDetails.Rows[i]["StartTime"].ToString() ?? "",
                                    StopTime = dtDetails.Rows[i]["StopTime"].ToString() ?? "",
                                    Duration = dtDetails.Rows[i]["Duration"].ToString() ?? "",
                                    Shift = dtDetails.Rows[i]["Shift"].ToString() ?? "",
                                    Actor = dtDetails.Rows[i]["Actor"].ToString() ?? "",
                                    CreateAt = dtDetails.Rows[i]["CreateAt"].ToString() ?? "",
                                    TunningInfo = new TunningEntity() 
                                    {
                                     Station= dtDetails.Rows[i]["TunningStation"].ToString() ?? "",
                                     Source= dtDetails.Rows[i]["TunningSource"].ToString() ?? "",
                                    }
                                });
                            }
                            Application.Current.Dispatcher.BeginInvoke((Action)(() => {
                                this.Details = tmpDetails;
                            }));
                        }
                        else
                        {
                            MessageBox.Show(arrMsg[1], "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        Application.Current.Dispatcher.BeginInvoke((Action)(() => {
                            this.IsVisibleLoading = Visibility.Collapsed;
                        }));
                    });

                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(string.Format("执行方法【{0}】出现错误【{1}】", nameof(ShowTunningDetailsInfoAsync), ex.Message), ex);
                    throw new Exception(ex.Message);
                }
            }
        }
        /// <summary>
        /// 机种下拉框搜索功能
        /// </summary>
        protected void FilterPN()
        {
            ComboPNOpen = true;
            //当是第一次过滤的时候备份原始数据
            //这样是为了当不输入搜索条件时添加原始数据到列表中
            //当输入搜索条件时生成过滤集合绑定当下拉列表中
            if (IsFirstFilterPNFlag)
            {
                backupPNs = new ObservableCollection<PartNumberEntity>();
                backupPNs = PNs;
                IsFirstFilterPNFlag = false;
            }
            //backupPNs = PNs;
            if (!string.IsNullOrEmpty(SearchPNText))
            {
                IEnumerable<PartNumberEntity> partNumberEntities = PNs.Where(s => s.PN.ToUpper().Contains(SearchPNText.ToUpper()));
                PNs = new ObservableCollection<PartNumberEntity>();
                foreach (var p in partNumberEntities)
                {
                    PNs.Add(p);
                }
            }
            else
            {
                PNs = backupPNs;
            }
            //OnPropertyChanged("Shops");
        }
        /// <summary>
        /// 工号下拉框搜索功能
        /// </summary>
        private void FilterActor()
        {
            IsOpenComboActorDropDown = true;
            //当是第一次过滤的时候备份原始数据
            //这样是为了当不输入搜索条件时添加原始数据到列表中
            //当输入搜索条件时生成过滤集合绑定当下拉列表中
            if (IsFirstFilterActorFlag)
            {
                backupActors = new ObservableCollection<EmployeesEntity>();
                backupActors = Actors;
                IsFirstFilterActorFlag = false;
            }
            if (!string.IsNullOrEmpty(SearchActorText))
            {
                IEnumerable<EmployeesEntity> actorEntities = Actors.Where(a=> a.UserNo.ToUpper().Contains(SearchActorText.ToUpper()));
                Actors = new ObservableCollection<EmployeesEntity>();
                foreach (var u in actorEntities)
                {
                    Actors.Add(u);
                }
            }
            else
            {
                Actors = backupActors;
            }
        }

        #endregion
    }
}
